import { Body, Controller, Delete, Get, Post, Put, Query } from '@nestjs/common'
import { QuestionService } from './question.service'
import { FindAllQueryDto } from './dto/FindAllQueryDto'
import { QuestionDto } from './dto/QuestionDto'
import { Public } from 'src/metadata/isPublicMetaData'

@Controller('question')
export class QuestionController {
  constructor(private readonly questionService: QuestionService) {}

  /**
   * 查询文件列表
   */
  @Get('list')
  findAll(@Query() query: FindAllQueryDto) {
    return this.questionService.findAll(query)
  }

  /**
   * 添加问卷
   * @param question 问卷信息
   */
  @Post('add')
  addQuestion(@Body() question: QuestionDto) {
    return this.questionService.addQuestion(question)
  }

  /**
   * 根据文件id查询文件信息
   */
  @Public()
  @Get('getInfo')
  getQuestionInfo(@Query() _id: string) {
    return this.questionService.getQuestionById(_id)
  }

  /**
   * 更新问卷
   * @param question 问卷信息
   */
  @Post('update')
  updateQuestion(@Body() question: QuestionDto) {
    return this.questionService.updateQuestion(question)
  }

  /**
   * 删除问卷
   * @param _id 问卷id
   */
  @Delete('delete')
  deleteQuestion(@Query() _id: string) {
    return this.questionService.deleteQuestion(_id)
  }

  /**
   * 恢复问卷
   * @param ids 问卷id
   */
  @Put('restore')
  restoreQuestion(@Body() { ids }: { ids: string[] }) {
    console.log(ids)
    return this.questionService.restoreQuestion(ids)
  }

  /**
   * 彻底删除问卷
   * @param ids 问卷id
   */
  @Put('remove')
  deleteQuestionCompletely(@Body() { ids }: { ids: string[] }) {
    return this.questionService.deleteQuestionCompletely(ids)
  }

  @Get('getAnswerList')
  getAnswerList(
    @Query('questionId') questionId: string,
    @Query('pageNum') pageNum: string = '1',
    @Query('pageSize') pageSize: string = '10'
  ) {
    return this.questionService.getAnswerList(questionId, pageNum, pageSize)
  }

  /**
   * 获取组件统计信息
   */
  @Get('stat')
  async getComponentStatistics(
    @Query('questionId') questionId: string,
    @Query('componentId') componentId: string,
    @Query('name') name: string
  ) {
    return this.questionService.getComponentStatistics(
      questionId,
      componentId,
      name
    )
  }

  @Get('getQuestionStatistics')
  async getQuestionStatistics() {
    return this.questionService.getQuestionStatistics()
  }
}
